<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<!-- head 头部-->
<head th:replace="admin/layout/include::head('配置管理','')"></head>
<style>
</style>
<body>
<!-- loading 动画-->
<div th:replace="admin/layout/include::loading"></div>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">内容配置</div>
        <div class="layui-card-body" style="min-height: 560px;max-width: 760px;">
            <form class="layui-form model-form"  lay-filter="biz">
                <div class="layui-form-item">
                    <label class="layui-form-label" lay-tips="开启评论，包括帖子和博客的评论" lay-direction="2">网站评论
                    <span class="icon-text"><i class="layui-icon layui-icon-tips" ></i></span>
                    </label>
                    <div class="layui-input-inline">
                       <input type="checkbox" id="gobalCommentState" name="gobalCommentState" lay-skin="switch" value="1" lay-text="开启|关闭">
                    </div>
                    <label class="layui-form-label" lay-tips="评论审核，不审核会默认评论审核通过" lay-direction="2">评论审核
                        <span class="icon-text"><i class="layui-icon layui-icon-tips"></i></span>
                    </label>
                    <div class="layui-input-inline">
                        <input type="checkbox" id="commentReview" name="commentReview" lay-skin="switch" value="1" lay-text="开启|关闭">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" lay-tips="点击文章的时候会默认1+这个值" lay-direction="2">文章点击
                        <span class="icon-text"><i class="layui-icon layui-icon-tips" ></i></span>
                    </label>
                    <div class="layui-input-block">
                        <input name="articleClickCalc"  class="layui-input" type="number" placeholder=""/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" lay-tips="侧边栏右边面板展示数量" lay-direction="2">侧栏展示数量
                        <span class="icon-text"><i class="layui-icon layui-icon-tips" ></i></span>
                    </label>
                    <div class="layui-input-block">
                        <input name="postSideShowTotal"  class="layui-input" type="number" placeholder=""/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">帖子尾巴</label>
                    <div class="layui-input-block">
                        <textarea name="postContentTail" class="layui-textarea build-edit"placeholder="支持HTML" style="min-height: 120px;"></textarea>
                    </div>
                </div>
                <div class="layui-form-item text-center" style="margin-top: 30px;">
                    <button class="layui-btn layui-btn-primary icon-btn" type="reset">
                        <i class="layui-icon">&#x1006;</i>重置
                    </button>
                    <button class="layui-btn icon-btn" lay-filter="submit" lay-submit>
                        <i class="layui-icon">&#xe605;</i>提交
                    </button>
                </div>
            </form>


        </div>
    </div>
</div>
</body>

<!-- js部分 -->
<div th:replace="admin/layout/include::js"></div>
<script>
    layui.use(['element','form', 'table', 'util', 'admin','fileChoose'], function () {
        var form = layui.form;
        var element = layui.element;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;
        var fileChoose = layui.fileChoose;

        var formUrl;  // 表单提交的action

        var configType = 'biz';
        B.get({
            url:'/admin/config/getConfig',
            data:{configType:configType},
            loading:true,
            success:function (res) {
                if(res.success){
                    form.val(configType,res.data);
                    $('#gobalCommentState').prop('checked',res.data.gobalCommentState=="1"?"checked":"");
                    $('#commentReview').prop('checked',res.data.commentReview=="1"?"checked":"");
                    form.render();
                }else{

                }
            }
        });
        function submit(data){
            // console.log(data) //当前容器的全部表单字段，名值对形式：{name: value}
            // 表单提交事件
            B.post({
                url: '/admin/config/saveMap',
                loading: true,
                data: data,
                success: function (data) {
                    if (data.success) {
                        layer.msg(data.msg, {icon: 1});
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                }
            });
        }
        form.on('submit(submit)', function(data){
            data.field.configType = configType;
            data.field.gobalCommentState = data.field.gobalCommentState=='1'?'1':'0';
            data.field.commentReview = data.field.commentReview=='1'?'1':'0';
            submit(data.field);
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


    });

</script>
</html>